﻿@*@model Bricks.Site.Models.FlowReceiptAccessControlView*@
@{
    ViewBag.Title = "AlterList";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        //当页面首次刷新的时候执行的事件
        initTable();
    });

    function initTable() {
        $('#myDataGrid').datagrid({
            url: '/Alter/GetAlterList',//?loginPersonType=' + $("#hLoginPersonType").val(),//一个用以从远程站点请求数据的超链接地址
            iconCls: 'icon-bricks',
            nowrap: true,//当数据长度超出列宽时将会自动截取
            autoRowHeight: false,
            striped: true,//设置为true将交替显示行背景
            collapsible: true,
            pagination: true,
            pageSize: 20,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',//表明该列是一个唯一列。
            singleSelect: true,
            fitColumns: true,
            sortName: 'ProjectName,ContractName',
            columns: [[
                        { title: 'AlterID', field: 'AlterID', hidden: true },
                        { title: 'HandleState', field: 'HandleState', hidden: true },
                        { title: '项目名称', field: 'ProjectName', width: 120, sortable: true },
                        { title: '标段名称', field: 'ContractName', width: 120, sortable: true },
                        {
                            title: '变更申请名称', field: 'AlterName', width: 240,
                            formatter:
                            function (value, row, index) {
                                return '<a href="#" onclick=PopAlter("' + row.HandleState + '","' + row.AlterID + '")>' + row.AlterName + '</a>';
                            }
                        },
                        { title: '变更类型', field: 'AlterType', width: 50, sortable: true },
                        { title: '申请日期', field: 'RequestDate', width: 100, sortable: true, formatter: function (value, rec) { if (value) { return dateConvert(value); } } },
                        { title: '增减金额（元）', field: 'AlterMoney', width: 70, sortable: true },
                        { title: '增减工期（天）', field: 'AlterDate', width: 70, sortable: true },
                        { title: '流程监控', field: 'ProcedureMonitor', width: 300, sortable: true },
            ]],
            toolbar: '#myToolBar',
            onLoadSuccess: function (data) {
                if (data.rows.length > 1) {
                    var tTable = $("#myDataGrid");
                    mergeCellsGroupByField(tTable, "ProjectName,ContractName", 0, data.rows.length);
                }
            },
            onDblClickRow: function (rowIndex, rowData) {
                PopAlter(rowData.HandleState, rowData.AlterID);
            }
        });
    }

    function PopAlter(handleState, id) {
        var processType = '1';
        if (handleState == "0") {
            processType = '2';
        }
        showMyWindow("#myWindow", "", "/Alter/Alter?MenuCode=Alter&sourceType=0&processType=" + processType + "&sourceID=&alterID=" + id, 1000, 500, true, true, true);
    }

    function PopAddAlter(department) {
        showMyWindow("#myWindow", "", "/Alter/Alter?MenuCode=Alter&sourceType=1&processType=&sourceID=&lastUpdateUserDepartment=" + department, 1000, 500, true, true, true);
    }

    var AlterList =
    {
        AddAlter: function () {
            $.post("/UserMenuAction/GetUserDepartmentForFlow?menuCode=AlterList", function (userDepartment) {
                if (userDepartment == "") {
                    showMyWindow("#myWindow", "选择机构", "/UserMenuAction/ShowOrgByUserForFlow?menuCode=AlterList", 500, 280, true, false);
                }
                else if (userDepartment == "**********") {
                    $.messager.alert('操作提示', '当前用户不属于任何机构，请先设置所属机构！', 'info');
                }
                else if (userDepartment == "++++++++++") {
                    $.messager.alert('操作提示', '当前用户的机构不属于流程申请配置机构，不能新增！', 'info');
                }
                else {
                    PopAddAlter(userDepartment);
                }
            });
        },

        DeleteAlter: function () {
            var selectAlter = $('#myDataGrid').datagrid('getSelections');
            if (selectAlter == "[]") {
                $.messager.alert('操作提示', '请选择要删除的行！', 'info');
            }
            else {
                $.messager.confirm('操作提示', "确认删除[ " + selectAlter[0].AlterName + " ]吗？", function (r) {
                    if (r) {
                        $.post("/Alter/DeleteSelectAlter?AlterID=" + selectAlter[0].AlterID, function (res) {
                            if (res == "Success") {
                                //移除删除的数据
                                $("#myDataGrid").datagrid("reload");
                                $("#myDataGrid").datagrid("clearSelections");
                                $.messager.alert('操作提示', '删除成功!', 'info');
                            }
                            else {
                                if (res == "") {
                                    $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                                }
                                else {
                                    $.messager.alert('操作提示', res, 'info');
                                }
                            }
                        });
                    }
                });
            }
        }
    }

    function cancelPopWindow(handleState) {
        if (handleState == "0") {
            initTable();
        }
        colseMyWindow("#myWindow");
    }

    function CloseWindow(data) {
        colseMyWindow("#myWindow");
        initTable();
        $.EasyuiSlide(data);
    }
</script>
@*<input type="hidden" id="hLoginPersonType" name="LoginPersonType" value="@Model.LoginPersonType" />*@
<table id="myDataGrid" fit="true"></table>
<div id="myToolBar">@Html.Raw(ViewBag.ToolBarInfo)</div>



